<template>
  <div>
      <mine-collapse :items="traceItems" @changeHeight="changeHeight" @allOption="allOption">
        <template #advice="data">
          <advice-collapse :adviceItem="data.data.content"></advice-collapse>
        </template>
        <template #comment="data">
          <comment-collapse :content="data.data.content"></comment-collapse>
        </template>
        <template #prod="data">
          <prod-collapse :content="data.data.content"></prod-collapse>
        </template>
      </mine-collapse>
  </div>
</template>

<script>
import mineCollapse from "@/components/Collapse.vue"
import adviceCollapse from "./advice.vue"
import commentCollapse from "./comment/comment.vue"
import prodCollapse from "./prod/prod.vue"
export default {
  components:{
    mineCollapse,
    adviceCollapse,
    commentCollapse,
    prodCollapse
  },
  data(){
    return {
      traceItems:[]
    }
  },
  created() {
    this.searchUserAllTrance()
  },
  computed:{
    addProdgrant() {
      return (
        this.$store.getters.user.status === "876ea4f21078c7d38e3b0bdc74a" ||
        this.$store.getters.user.status === "d630fbb5fd6026ccb4af0eb68d3"
      );
    },
  },
  methods:{
    searchUserAllTrance(){
      this.$axios.post("/trace/trace",{
        username:this.$store.getters.user.username
      }).then(res=>{
        let traceItems = res.data.data.map((item,index)=>{
          let title = "",id = "",ifShow = true
          switch(index){
            case 0:title = "作品",id = "prod";break;
            case 1:title = "留言",id = "advice";break;
            case 2:title = "评论",id = "comment";break;
          }
          return {title,content:item,status:false,ifShow,id}
        })
        if(this.addProdgrant){
          this.traceItems = traceItems
        }else{
          this.traceItems = traceItems.map(item=>item.id!=='prod')
        }
      })
    },
    changeHeight(index){
      this.traceItems.forEach((item,i)=>{
        if(i===index){
          this.$set(this.traceItems,i,{...item,status:!item.status})
        }
      })
    },
    allOption(status){
      this.traceItems.forEach((item,i)=>{
          this.$set(this.traceItems,i,{...item,status:!status})
      })
    }
  }
}
</script>

<style>

</style>